package sf.database.dao;

import sf.database.jdbc.sql.PreparedStatementCreator;
import sf.database.template.TemplateType;

/**
 * db执行上下文
 */
public class DBContext {
    /**
     * 数据源名称
     */
    private String dataSource;

    /**
     * 是否无事务,对jta事务无效
     */
    private boolean noTransaction;

    /**
     * 查询超时设置(s)
     */
    private int queryTimeout;

    /**
     * 是否使用tail
     */
    private boolean useTail;
    /**
     * 是否保留DBObject中的updateMap
     */
    private boolean keepUpdate;

    /**
     * 动态表名(只针对对象操作生效,多表请勿使用,会产生意想不到的错误.)
     */
    private String dynamicTableName;

    /**
     * sql模板类型,提供运行时改变模板引擎的方法
     */
    private TemplateType sqlTemplateType;

    /**
     * 个性化PreparedStatement创建,主要是为了流式迭代使用
     */
    private PreparedStatementCreator statementCreator;

    /**
     * DBClient或者是R2dbcTemplate
     */
    protected Object client;

    /**
     * 是否使用对象延迟功能,该功能和hibernate的延迟加载类似.
     * 为了避免循环查询,当前暂时只支持一层查询.已解决json序列化堆栈溢出的问题.
     */
    private boolean useLazyLoad;

    public DBContext() {

    }

    /**
     * @param dataSource 数据源名称
     */
    public DBContext(String dataSource) {
        this.dataSource = dataSource;
    }

    /**
     * @param noTransaction 使用原始连接
     */
    public DBContext(boolean noTransaction) {
        this.noTransaction = noTransaction;
    }

    /**
     * @param dataSource    数据源名称
     * @param noTransaction 使用原始连接
     */
    public DBContext(String dataSource, boolean noTransaction) {
        this.dataSource = dataSource;
        this.noTransaction = noTransaction;
    }

    public String getDataSource() {
        return dataSource;
    }

    public void setDataSource(String dataSource) {
        this.dataSource = dataSource;
    }

    public boolean isNoTransaction() {
        return noTransaction;
    }

    public void setNoTransaction(boolean noTransaction) {
        this.noTransaction = noTransaction;
    }

    public int getQueryTimeout() {
        return queryTimeout;
    }

    public void setQueryTimeout(int queryTimeout) {
        this.queryTimeout = queryTimeout;
    }

    public boolean isUseTail() {
        return useTail;
    }

    public void setUseTail(boolean useTail) {
        this.useTail = useTail;
    }

    public boolean isKeepUpdate() {
        return keepUpdate;
    }

    public void setKeepUpdate(boolean keepUpdate) {
        this.keepUpdate = keepUpdate;
    }

    public String getDynamicTableName() {
        return dynamicTableName;
    }

    public void setDynamicTableName(String dynamicTableName) {
        this.dynamicTableName = dynamicTableName;
    }

    public TemplateType getSqlTemplateType() {
        return sqlTemplateType;
    }

    public void setSqlTemplateType(TemplateType sqlTemplateType) {
        this.sqlTemplateType = sqlTemplateType;
    }

    public PreparedStatementCreator getStatementCreator() {
        return statementCreator;
    }

    public void setStatementCreator(PreparedStatementCreator statementCreator) {
        this.statementCreator = statementCreator;
    }

    public void setClient(Object client) {
        this.client = client;
    }

    public Object getClient() {
        return client;
    }

    public boolean isUseLazyLoad() {
        return useLazyLoad;
    }

    public void setUseLazyLoad(boolean useLazyLoad) {
        this.useLazyLoad = useLazyLoad;
    }
}
